package yawning.mew.character;

import java.util.Arrays;
import java.util.HashSet;

import yawning.mew.equipment.EquipSet;
import yawning.mew.equipment.EquipSet.Slot;
import yawning.mew.equipment.RawItem;
import yawning.mew.equipment.RawItem.Property;

public class EquipSetToonBuilder {
	private Toon mBaseToon;
	private EquipSet mEquipSet;
	
	public EquipSetToonBuilder setBaseToon(Toon baseToon) {
		mBaseToon = baseToon;
		return this;
	}
	
	public EquipSetToonBuilder setEquipSet(EquipSet es) {
		mEquipSet = es;
		return this;
	}
	
	public Toon build() {
		Toon t = new Toon();
		
	    t.level = mBaseToon.level;
	    t.mClass = mBaseToon.mClass;
	    t.mRace = mBaseToon.mRace;
	    
	    t.glyphs = new HashSet<Glyph>(mBaseToon.glyphs);
	    t.talents = Arrays.copyOf(mBaseToon.talents, mBaseToon.talents.length);
	    t.mTalentSpec = mBaseToon.mTalentSpec;
	    
		// TODO: Add class/level modifiers
		
    	t.strength = mEquipSet.sumProperty(Property.STRENGTH) + t.mRace.getBaseStrength();
    	t.agility = mEquipSet.sumProperty(Property.AGILITY) + t.mRace.getBaseAgility();
    	t.stamina = mEquipSet.sumProperty(Property.STAMINA) + t.mRace.getBaseStamina();
    	t.intellect = mEquipSet.sumProperty(Property.INTELLECT) + t.mRace.getBaseIntellect();
    	t.spirit = mEquipSet.sumProperty(Property.SPIRIT) + t.mRace.getBaseSpirit();
    	t.armor = mEquipSet.sumProperty(Property.ARMOR);
    	t.attackPower = mEquipSet.sumProperty(Property.ATTACK_POWER);
    	t.hasteRating = mEquipSet.sumProperty(Property.HASTE_RATING);
    	t.critRating = mEquipSet.sumProperty(Property.CRIT_RATING);
    	t.hitRating = mEquipSet.sumProperty(Property.HIT_RATING);
    	t.expertiseRating = mEquipSet.sumProperty(Property.EXPERTISE_RATING);
    	t.masteryRating = mEquipSet.sumProperty(Property.MASTERY_RATING);
    	
    	if (mEquipSet.equipmentMap.containsKey(Slot.MAIN_HAND)) {
	    	RawItem rawItem = mEquipSet.equipmentMap.get(Slot.MAIN_HAND).mItem;
	    	t.weaponTop = rawItem.properties.get(Property.MELEE_DMG_MAX);
	    	t.weaponBottom = rawItem.properties.get(Property.MELEE_DMG_MIN);
	    	t.weaponSpeed = rawItem.properties.get(Property.MELEE_SPEED);
    	}
    	
    	// TODO: Really check 
    	t.isArmorSpec = true;
	    
		return t;
	}
}
